<template>
  <div>
    <div>
      <label>仿真时长（simDuration）：
        <input v-model.number="simDuration" type="number" placeholder="请输入仿真时长" />
      </label>
    </div>
    <div>
      <label>采样时间（sampleTime）：
        <input v-model.number="sampleTime" type="number" placeholder="请输入采样时间" />
      </label>
    </div>
    <div>
      <label>卫星ID（satId）：
        <input v-model.number="satId" type="number" placeholder="请输入卫星ID" />
      </label>
    </div>

    <button @click="simulate">发送请求</button>

    <div v-if="responseData">
      <h3>响应数据：</h3>
      <pre>{{ formattedResponse }}</pre>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      simDuration: 1,  // 默认值可改
      sampleTime: 1,
      satId: 1,
      responseData: null,
    };
  },
  computed: {
    formattedResponse() {
      return JSON.stringify(this.responseData, null, 2);
    }
  },
  methods: {
    async simulate() {
      try {
        const params = {
          simDuration: this.simDuration,
          sampleTime: this.sampleTime,
          satId: this.satId
        };
        const res = await axios.get('http://localhost:8080/api/scene/simulate', { params });
        if (res.data.code === 200) {
          this.responseData = res.data.data;
        } else {
          this.responseData = { error: res.data.message || '请求失败' };
        }
      } catch (error) {
        this.responseData = { error: error.message || '请求异常' };
      }
    }
  }
};
</script>

<style scoped>
input {
  margin: 5px;
  padding: 5px;
  width: 220px;
}

pre {
  background: #f5f5f5;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}
</style>
